<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.ArrayList"%>
<%@page import="dao.Thanhviendao"%>
<%@page import="model.Thanhvienmodel"%>
<head>
<style type="text/css">
.mautrang{color:white;}
.mauden{color:#000000;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script type="text/javascript">
	function xuLyCapNhat() {
		var select = document.getElementsByName("select");
		//alert(select.length);
		var count = 0;
		var idselected = -1;
		for(var i = 0; i < select.length; i++) {
			if (select[i].checked) {
				count++;
				idselected = select[i].value;
				//alert(select[i].value);	
			}
		}	
		if (count != 1) {
			alert('Khong cap nhat duoc nhieu dong');
			return false;
		}			
		var link = "Themmoi.jsp?updateID=" + idselected;
		document.getElementById("linkUpdate").href = link;
		return true;
	}
</script>

</head>
<body>
<h1>Dang nhap thanh cong</h1>
<h2>Xin chao
<%
	//String TenDangNhap=request.getAttribute("TenCanGan").toString();
	//String Vaitro=request.getAttribute("Vaitro").toString();
	String TenDangNhap=request.getSession().getAttribute("TenCanGan").toString();
	String Vaitro=request.getSession().getAttribute("Vaitro").toString();
	out.println(TenDangNhap);
 %>
</h2>
Vai tro la <%=Vaitro %>
<table border="1" bgcolor="blue">
<tr class="mauden">
	<th>&nbsp;</th>
	<th>ID</th>
	<th>TEN DANG NHAP</th>
	<th>MAT KHAU</th>
	<th>VAI TRO</th>
	<th>GHI CHU</th>
</tr>
<%
	ArrayList<Thanhvienmodel> listThanhvien = Thanhviendao.getallThanhvien();
	for(Thanhvienmodel model: listThanhvien){
		out.print("<tr class='mautrang'>");
		out.print("<td> <input type='checkbox' name='select' value='"+model.getID()+"'/></td>");
		out.print("<td>"+model.getID()+"</td>");
		out.print("<td>"+model.getTENDN()+"</td>");
		out.print("<td>"+model.getMATKHAU()+"</td>");
		out.print("<td>"+model.getVAITRO()+"</td>");
		out.print("<td>"+model.getGHICHU()+"</td>");
		out.print("</tr>");
	}
	
 %>
</table>
<a href="Themmoi.jsp">Them moi</a> <br/>
<a id="linkUpdate" href="Themmoi.jsp" onclick="return xuLyCapNhat();"> Cap Nhat</a>
</body>
</html>